package sjtu.ist.warehouse4ws.dao.cust;

import java.util.List;

import org.hibernate.SQLQuery;

import sjtu.ist.warehouse4ws.dao.BaseDaoHibernate;
import sjtu.ist.warehouse4ws.model.CustColumn;
import sjtu.ist.warehouse4ws.model.CustDepartment;

public class CustColumnDaoHibernate extends BaseDaoHibernate<CustColumn> implements CustColumnDao {
	public void createTable(String custName){
		String sql="CREATE TABLE `"+custName+"_cust_column` ("
		  +"`id` int(32) NOT NULL AUTO_INCREMENT,"
		  +"`tablename` varchar(150) DEFAULT NULL,"
		  +"`columnname` varchar(100) DEFAULT NULL,"
		  +"`type` int(10) DEFAULT NULL,"
		  +"PRIMARY KEY (`id`)"
		  +")";
	SQLQuery query=getSession().createSQLQuery(sql);
	query.executeUpdate();
	}

	@Override
	public List<CustColumn> getAll() {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from CustColumn");
	}

	@Override
	public List<CustColumn> getByTable(String tablename) {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from CustColumn c where c.tablename='"+tablename+"'");
	}

	@Override
	public void addColumn(CustColumn column) {
		// TODO Auto-generated method stub
		getHibernateTemplate().save("CustColumn", column);
	}
}
